package com.ordertracker.entity;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Description of class.
 * Created 1/18/13 2:54 PM
 *
 * @author andrey.rodin@playtech.com
 */

@XmlRootElement
public class Client extends VersionedEntity {

    private static final long serialVersionUID = -8884793241380189224L;
    private String name;
    private String code;
    private String description;
    private Organization organization;

    public Client() {
    }

    public Client(String name, String code, String description, Organization organization) {
        this.name = name;
        this.code = code;
        this.description = description;
        this.organization = organization;
    }

    @XmlElement(nillable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlElement
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @XmlElement
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @XmlElement
    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Client)) return false;
        if (!super.equals(o)) return false;

        Client client = (Client) o;

        if (!code.equals(client.code)) return false;
        if (description != null ? !description.equals(client.description) : client.description != null) return false;
        if (!name.equals(client.name)) return false;
        if (!organization.equals(client.getOrganization())) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + code.hashCode();
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + organization.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "Client{" +
                "name='" + name + '\'' +
                ", code=" + code +
                ", description='" + description + '\'' +
                ", organization=" + organization.toString() +
                ", " + super.toString();
    }
}
